package com.ship.control.impl;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.springframework.web.servlet.ModelAndView;

import com.ship.control.AbstractAdminCommandController;
import com.ship.control.search.MainlandMaterialSearchCond;
import com.ship.control.search.SearchStat;
import com.ship.entity.MainlandMaterial;
import com.ship.entity.ShipInfo;
import com.ship.entity.ShipLog;
import com.ship.service.ShipService;

/**
 * 船舶作业日志
 * @author wqf
 * @version  Nov 24, 2011 12:00:53 PM
 */
public class ShipMainlandMaterialListController extends AbstractAdminCommandController {

	public ShipMainlandMaterialListController(){
		this.setCommandClass(MainlandMaterialSearchCond.class);
	}
	

	protected ModelAndView executeRequest(HttpServletRequest request,HttpServletResponse response,Object command)
		throws Exception{
		
		MainlandMaterialSearchCond mainlandMaterialSearchCond=(MainlandMaterialSearchCond)command;
		
		String shipInfoId = request.getParameter("id");
				
		ModelAndView mav=new ModelAndView(this.view);
		mainlandMaterialSearchCond.setPageSize(10L);
		
		if(StringUtils.isNotBlank(shipInfoId)){
			mainlandMaterialSearchCond.setShipInfoId(Long.parseLong(shipInfoId));
			ShipInfo shipInfo = this.shipService.getShipInfoById(Long.parseLong(shipInfoId));
			mav.addObject("shipInfo", shipInfo);
						
			SearchStat searchStat=this.shipService.getSearchStat(MainlandMaterial.class, mainlandMaterialSearchCond);
			List<MainlandMaterial> mainlandMaterialList=this.shipService.getMainlandMaterialList(mainlandMaterialSearchCond);
			mav.addObject("searchStat", searchStat);
			mav.addObject("mainlandMaterialList", mainlandMaterialList);
			mav.addObject("mainlandMaterialSearchCond", mainlandMaterialSearchCond);
		}
		
		return mav;
		
	}
	
	public void setShipService(ShipService shipService) {
		this.shipService = shipService;
	}

	private String view;
	private ShipService shipService;
	
	public void setView(String view) {
		this.view = view;
	}

}
